/**
 * 
 */
package edu.arizona.bio5.onto.decomposition.persistent.file;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Reader;

import edu.arizona.bio5.onto.decomposition.persistent.ADPersistenceException;
import edu.arizona.bio5.onto.decomposition.persistent.AbstractAtomLoader;
import edu.arizona.bio5.onto.decomposition.persistent.PersistentAtom;

/**
 * @author Pavel Klinov
 *
 */
public class DiskAtomLoader extends AbstractAtomLoader {

	private File m_dir = null;
	
	public DiskAtomLoader(File dir) {
		
		m_dir = dir;
	}
	
	@Override
	protected Reader getOntologySourceReader(PersistentAtom atom) throws ADPersistenceException {
		//Locate atom's file first
		File atomFile = new File(m_dir.getAbsolutePath() + "/atom" + atom.getID().toString() + ".owl");
				
		if (!atomFile.exists()) throw new ADPersistenceException("Atom's file not found" + atomFile.getAbsolutePath());
		
		try {
			return new FileReader(atomFile);
			
		} catch (FileNotFoundException e) {
			throw new ADPersistenceException(e);
		}
	}

	@Override
	public void close() {}
}